<?php
namespace Home\Controller;
use Home\Controller\BaseController;
// +----------------------------------------------------------------------
// | Date:2017年1月11日
// +----------------------------------------------------------------------
// | Author: EK_熊<1439527494@qq.com>
// +----------------------------------------------------------------------
// | Description: 此文件作用于****
// +----------------------------------------------------------------------
class MyMessageController extends BaseController{
    
    
    protected $model = '';
    public function _initialize(){
        parent::_initialize();
        $this->model = D('Comment');
        $this->assign('showSearchbar','hide');//隐藏顶部的搜索框
    }
    
    public function index(){
        
        $where['to_uid'] = $this->uid;
        $where['msg.status'] = 1;
        $field = 'msg.pro_id,msg.content as content,title,uid,to_uid,msg.created_time';
        $order = 'msg.created_time desc';
        
        //改变未读消息状态
        $this->model->read_all_comment($this->uid);
        
        $count = $this->model->alias('msg')
            ->join('LEFT JOIN __PRODUCT__ pro ON pro.id = msg.pro_id')
            ->where($where)
            ->count();
        $page = new \Think\Page($count,10);
        
        $showPage = $page->show();
        $this->assign("page", $showPage);
        
        $list =  $this->model->alias('msg')
        ->join('LEFT JOIN __PRODUCT__ pro ON pro.id = msg.pro_id')
        ->where($where)
        ->order($order)
        ->limit(10)
        ->field($field)
        ->select();
        
        $list = $this->model->append_nickname($list);//拼接昵称
        $this->assign('list',$list);
        $this->display();
    }
    
}